package com.bw.a3_27zk

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.SpannableStringBuilder
import android.view.View
import android.view.View.OnClickListener
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ClickUtils
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.TouchUtils
import com.bw.a3_27zk.databinding.ActivityRegisterBinding
import com.bw.a3_27zk.login.LoginViewModel
import com.bw.base.mvvm.BaseActivity

@Route(path = "/app/RegisterActivity")
class RegisterActivity : BaseActivity<ActivityRegisterBinding,LoginViewModel>() {


    override fun initView() {

        //跳转到登陆
        binding.login.setOnClickListener{
            ARouter.getInstance().build("/app/login/LoginActivity").navigation()
        }
        //富文本
//        val toString = binding.cb.text.toString()
//        val spannableStringBuilder = SpannableStringBuilder(toString)
//        fun  click() :String {
//            var click = ToastUtils.showLong("点击了")
//
//            return click()
//            }
//
//
//        //富文本点击事件
//        spannableStringBuilder.setSpan(click(),9,16,0)
//        spannableStringBuilder.setSpan(click(),17,22,0)

//        binding.cb.text = spannableStringBuilder

        binding.register.setOnClickListener {
            if(!binding.cb.isChecked){
                ToastUtils.showLong("请先勾选用户协议")
            } else{
                val map = mutableMapOf<String,String>()
                map.put("username",binding.et2.text.toString())
                map.put("password",binding.et3.text.toString())
                map.put("repassword",binding.et4.text.toString())
                viewModel.register(map)
            }



        }
    }

    override fun initData() {
        viewModel.registerSuccess.observe(this){
            ARouter.getInstance().build("/app/login/LoginActivity").navigation()
            SPUtils.getInstance().put("phone",binding.et2.text.toString())
            SPUtils.getInstance().put("pwd",binding.et3.text.toString())
        }
        viewModel.registerFail.observe(this){
            ToastUtils.showLong(it)
        }
    }

    override fun getViewModel(): Class<LoginViewModel> = LoginViewModel::class.java

    override fun getLayoutId(): Int = R.layout.activity_register
}